package com.iwaster.domain;

import java.util.List;

/**
 * wgy 2019/4/23 14:31
 */
public class PageBean<T> {
    //五个属性
    private int pageIndex;
    private int pageSize;
    private long totalSize;
    private int pageCount;

    private List<T> data;

    //开始和结束页码
    private int startPage;
    private int endPage;


    public PageBean(int pageIndex, int pageSize, long totalSize, List<T> data) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.totalSize = totalSize;
        this.data = data;


        //计算pageCount
        pageCount= (int) (totalSize%pageSize==0?totalSize/pageSize:totalSize/pageSize+1);

        //设置开始页码和结束页码
        //1正常情况
        startPage=pageIndex-4;
        endPage=pageIndex+5;
        //2当前页面小于5
        if(pageIndex<5){
            startPage=1;
            endPage=10;
        }
        //3当前页面大于总页码-5
        if(pageIndex>pageCount-5){
            startPage=pageCount-9;
            endPage=pageCount;
        }

        //4总页码小于10
        if(pageCount<=10){
            startPage=1;
            endPage=pageCount;
        }


    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(long totalSize) {
        this.totalSize = totalSize;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getStartPage() {
        return startPage;
    }

    public void setStartPage(int startPage) {
        this.startPage = startPage;
    }

    public int getEndPage() {
        return endPage;
    }

    public void setEndPage(int endPage) {
        this.endPage= endPage;
    }
}
